// Written by Craig'n'Dave
using System;
using System.Collections.Generic;
// Breadth first traversal
namespace ConsoleApp1
{
    class Program
    {
        static List<string> bft(Dictionary<string, List<string>> graph, string current_vertex)
        {
            List<string> visited = new List<string>();
            Queue<string> q = new Queue<string>();
            visited.Add(current_vertex);
            while (current_vertex != null)
            {
                foreach (var vertex in graph.GetValueOrDefault(current_vertex))
                {
                    if (!visited.Contains(vertex))
                    {
                        q.Enqueue(vertex);
                        visited.Add(vertex);
                    }
                }
                if (q.Count > 0)
                {
                    current_vertex = q.Dequeue();
                }
                else
                {
                    current_vertex = null;
                }
            }
            return visited;
        }
        // Main program starts here
        static void Main(string[] args)
        {
            var graph = new Dictionary<string, List<string>>()
            {
                { "A", new List<string>() { "B", "C", "D"} },
                { "B", new List<string>() { "A", "E" } },
                { "C", new List<string>() { "A", "D" } },
                { "D", new List<string>() { "A", "C", "F" } },
                { "E", new List<string>() { "B", "G" } },
                { "F", new List<string>() { "D" } },
                { "G", new List<string>() { "E" } }
            };

            List<string> visited = new List<string>();
            visited = bft(graph, "A");
            Console.WriteLine(string.Join(", ", visited));
        }
    }
}
